#pragma once

#include <AVUIVisual3D.h>
#include <AVUIVisual3DCollection.h>

namespace AVUI {

class Model3D;
class Transform3D;
    
class ModelVisual3D : public Visual3D
{
public:
    ModelVisual3D() : m_children(this) { };
    ~ModelVisual3D() 
    { 
        m_children.InvalidateWeakReferences();
    }

    DECLARE_ELEMENT(ModelVisual3D, Visual3D);

    DECLARE_DEPENDENCY_PROPERTY(Content);
    TRefCountedPtr<Model3D> get_Content() { return (Model3D*)(Object*)GetValue(get_ContentProperty()); }
    void set_Content(Model3D* pValue) { SetValue(get_ContentProperty(), (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(Transform);
    TRefCountedPtr<Transform3D> get_Transform() { return (Transform3D*)(Object*)GetValue(get_TransformProperty()); }
    void set_Transform(Transform3D* pValue) { SetValue(get_TransformProperty(), (Object*)pValue); } 

    IMPLEMENT_READONLY_REFERENCE_PROPERTY(Children, Visual3DCollection, true);

    Visual3DCollection* get_Children() { return &m_children; }

    virtual Visual3D* GetVisual3DChild(int index) AVUI_OVERRIDE { return m_children[index]; }
    int get_Visual3DChildrenCount() AVUI_OVERRIDE { return m_children.get_Count(); }

private:
    static void StaticConstructor();
    static void ContentPropertyChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);

    Visual3DCollection m_children;
};


}; // namespace AVUI
